#!/usr/bin/python
# encoding=utf-8

"""
@Author  :  Don
@Date    :  2021/11/03 20:34
@Desc    :
"""


import random
import copy
import itertools
from sys import stdout


def pare_wise(option):
    """pairwise算法"""
    cp = []  # 笛卡尔积
    s = []  # 两两拆分
    for x in eval('itertools.product' + str(tuple(option))):
        cp.append(x)
        s.append([i for i in itertools.combinations(x, 2)])
    del_row = []
    s2 = copy.deepcopy(s)
    for i in range(len(s)):  # 对每行用例进行匹配
        t = 0
        for j in range(len(s[i])):  # 对每行用例的两两拆分进行判断，是否出现在其他行
            flag = False
            for i2 in [x for x in range(len(s2)) if s2[x] != s[i]]:  # 找同一列
                if s[i][j] == s2[i2][j]:
                    t = t + 1
                    flag = True
                    break
            if not flag:  # 同一列没找到，不用找剩余列了
                break
        if t == len(s[i]):
            del_row.append(i)
            s2.remove(s[i])
    res = [cp[i] for i in range(len(cp)) if i not in del_row]
    return res


def deal_with_multi_options(option_list):
    multi_choices = []
    list_result = []
    # list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
    if len(option_list) > 2:
        for i in range(len(option_list)//2):
            for j in range(len(option_list)):
                list2 = random.choices(option_list)
                list_result += list2
            result = set(list_result)
            result = list(result)
            if len(result) == 1:
                continue
            elif len(result) == len(option_list):
                continue
            else:
                print(result)
                select_value = ''
                for ele in result:
                    if ele != result[-1]:
                        select_value += f'{ele}、'
                    else:
                        select_value += ele
                multi_choices.append(select_value)
    multi_choices = list(set(multi_choices))
    return multi_choices


def deal_with_multi_for_single(option_list):
    list_result = []
    if len(option_list) > 5:
        for i in range(5):
            list2 = random.choices(option_list)
            list_result += list2
    single_choice = list(set(list_result))
    return single_choice


def generate_search_case_1(option_list, titles, steps, expect_results, field_name, page_name):
    for i1 in range(len(option_list)):
        titles.append(f'【单一条件查询】查询条件{field_name}输入{option_list[i1]}')
        steps.append(
            f"1.进入{page_name}页面；2.在查询条件{field_name}输入{option_list[i1]}；3.其他查询条件保持默认；4.点击查询")
        expect_results.append("查询结果正确无误")


if __name__ == '__main__':
    # pl = [['M', 'O', 'P'], ['W', 'L', 'I'], ['C', 'E'],['B', 'D'],['H']]
    # pl = [['M', 'O', 'P']]
    # pl = [['条件1'], ['条件2'], ['条件3'], ['条件4'], ['条件5']]
    # a = pare_wise(pl)
    # print(a)
    # for k in a:
    #     print(k)
    list1 = ['A', 'B', 'C', 'D', 'E', 'F']
    print(deal_with_multi_for_single(list1))